import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { getWeekMonthQuarterYear } from '/@/utils';
//列表数据
export const columns: BasicColumn[] = [
  {
    title: '会员信息',
    align: 'center',
    dataIndex: 'code',
    slots: { customRender: 'userInfo' },
    resizable: true,
    width: 200,
  },
  {
    title: '渠道来源',
    align: 'center',
    dataIndex: 'cardSourceId_dictText',
    resizable: true,
  },
  {
    title: '类型',
    align: 'center',
    dataIndex: 'cardStyleId_dictText',
    resizable: true,
  },
  {
    title: '申请状态',
    align: 'center',
    dataIndex: 'state_dictText',
    resizable: true,
  },

  {
    title: '收购价',
    align: 'center',
    dataIndex: 'buyPrice',
    resizable: true,
  },
  {
    title: '所属品牌/卡种',
    align: 'center',
    dataIndex: 'brandName',
    slots: { customRender: 'bindAndCard' },
    resizable: true,
  },
  {
    title: '上传时间',
    align: 'center',
    dataIndex: 'createTime',
    resizable: true,
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: '品牌/卡种名称',
    field: 'name',
    component: 'Input',
  },
  {
    label: '渠道来源',
    field: 'cardSourceId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'app_card_source,name,id',
    },
  },
  {
    label: '类型',
    field: 'cardStyleId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'app_card_style,name,id',
    },
  },
  {
    label: '类别',
    field: 'oneId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'app_category_one,name,id',
    },
  },
  {
    label: '会员/用户',
    field: 'memberId',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'app_member,nick_name,id',
      showSearch: true,
    },
    //colProps: {span: 6},
  },
  {
    label: '当前状态',
    field: 'state',
    component: 'Select',
    componentProps: {
      options: [
        { value: 2, label: '待审核' },
        { value: 4, label: '驳回' },
        { value: 1, label: '成功' },
      ],
    },
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '兑换码',
    field: 'code',
    component: 'Input',
  },
  {
    label: '券码',
    field: 'couponCode',
    component: 'JImageUpload',
    componentProps: {
      fileMax: 1,
    },
  },
  {
    label: '使用状态',
    field: 'useState',
    defaultValue: '0',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'card_use_state',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入使用状态!' }];
    },
    dynamicDisabled: true,
  },
  {
    label: '上传用户',
    field: 'memberId',
    defaultValue: 'admin',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'app_member,nick_name,id',
    },
    dynamicDisabled: true,
  },
  {
    label: '状态',
    field: 'state',
    defaultValue: '1',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'card_state',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入状态!' }];
    },
  },
  {
    label: '上架状态',
    field: 'groundingState',
    defaultValue: '1',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'card_grounding',
    },
    dynamicRules: ({ model, schema }) => {
      return [{ required: true, message: '请输入上架状态!' }];
    },
  },
  {
    label: '卡券名称',
    field: 'name',
    component: 'Input',
  },
  {
    label: '卡券来源',
    field: 'cardSourceId',
    component: 'Input',
  },
  {
    label: '卡种类型',
    field: 'cardStyleId',
    component: 'Input',
  },
  {
    label: '城市',
    field: 'city',
    component: 'Input',
  },
  {
    label: '进货价',
    field: 'buyPrice',
    component: 'InputNumber',
  },
  {
    label: '失效时间',
    field: 'lifespan',
    component: 'DatePicker',
    componentProps: {
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
  {
    label: '是否标记优先',
    field: 'isPriority',
    component: 'InputNumber',
  },
  {
    label: '是否标红',
    field: 'isRed',
    component: 'InputNumber',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];

// 高级查询数据
export const superQuerySchema = {
  code: { title: '兑换码', order: 0, view: 'text', type: 'string' },
  couponCode: { title: '券码', order: 1, view: 'image', type: 'string' },
  useState: { title: '使用状态', order: 2, view: 'list', type: 'string', dictCode: 'card_use_state' },
  memberId: { title: '上传用户', order: 3, view: 'list', type: 'string', dictTable: 'app_member', dictCode: 'id', dictText: 'nick_name' },
  useTime: { title: '使用时间', order: 4, view: 'datetime', type: 'string' },
  state: { title: '状态', order: 5, view: 'list', type: 'string', dictCode: 'card_state' },
  groundingState: { title: '上架状态', order: 6, view: 'list', type: 'string', dictCode: 'card_grounding' },
  name: { title: '卡券名称', order: 7, view: 'text', type: 'string' },
  cardSourceId: { title: '卡券来源', order: 8, view: 'text', type: 'string' },
  cardStyleId: { title: '卡种类型', order: 9, view: 'text', type: 'string' },
  city: { title: '城市', order: 10, view: 'text', type: 'string' },
  buyPrice: { title: '进货价', order: 11, view: 'number', type: 'number' },
  lifespan: { title: '失效时间', order: 12, view: 'datetime', type: 'string' },
  remark: { title: '备注', order: 13, view: 'text', type: 'string' },
  isPriority: { title: '是否标记优先', order: 14, view: 'number', type: 'number' },
  isRed: { title: '是否标红', order: 15, view: 'number', type: 'number' },
};

/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
